﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WinFormsCrawler
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            LogInfo.Instance._listBox = listBox1;
            textBox1.Text = @"http://www.cnblogs.com/dstang2000/";
        }

        Crawler myCrawler = new Crawler();

        Thread _Thread = null;
        private void StartBTN_Click(object sender, EventArgs e)
        {
            if(StartBTN.Text == "开始爬取")
            {
                _Thread = new Thread(new ThreadStart(() => {
                    myCrawler.urls.Clear();
                    
                    myCrawler.InitURL = textBox1.Text ;

                    myCrawler.urls.Add(textBox1.Text,false);
                    myCrawler.Start();
                }));
                _Thread.Start();
                StartBTN.Text = "停止";
            }
            else
            {
                
                if (_Thread != null)
                {
                    myCrawler._IsRunning = false;
                    Thread.Sleep(200);
                    LogInfo.Instance.Log("爬取结束");
                }
                StartBTN.Text = "开始爬取";
            }
        }
    }
}
